<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { onMounted, onUnmounted } from 'vue'

import { activeDate, changeDay, changeMonth, clear, displayDate, result, init, toInfo } from './data'
import { imagePath, maskStyle } from '@/libs/file-utils'

const img_bg = imagePath('quiz/luckday/detail/bg.jpg')
const img_logo = imagePath('quiz/luckday/detail/logo.png')
const img_title = imagePath('quiz/luckday/detail/title.png')
const info_bg = imagePath('quiz/luckday/detail/info-bg.png')
const icon_back = imagePath('icon-back.svg')

onMounted(init)
onUnmounted(clear)
</script>

<template>
  <PageWrapper
    name="quiz-luckday-detail"
    :pageStyle="{ backgroundImage: img_bg }"
  >
    <div class="calendar">
      <div
        class="logo"
        :style="{ backgroundImage: img_logo }"
      ></div>
      <div
        class="title"
        :style="{ backgroundImage: img_title }"
      ></div>

      <div class="date">
        {{ displayDate }}
        <div class="change">
          <div class="inner">
            <div @click="changeMonth(-1)">上个月</div>
            <div class="divider"></div>
            <div @click="changeMonth(1)">下个月</div>
          </div>
        </div>
      </div>
      <div class="week">
        <div>一</div>
        <div>二</div>
        <div>三</div>
        <div>四</div>
        <div>五</div>
        <div>六</div>
        <div>日</div>
      </div>
      <div class="day">
        <div
          v-for="(item, index) in result"
          :key="index"
          class="item"
          :class="{
            right: item.borderRight,
            bottom: item.borderBottom,
            active: activeDate === item.data?.date
          }"
          @click="changeDay(item.data)"
        >
          {{ item.data?.date }}
          <div
            v-if="activeDate === item.data?.date"
            class="info"
            :style="`${item.leftInfo ? 'right' : 'left'}:100%;background-image:${info_bg}`"
          >
            <div
              class="top-bar"
              @click="toInfo(item.data)"
            >
              看吉凶日
              <div
                class="icon"
                :style="maskStyle(icon_back)"
              ></div>
            </div>
            <div class="box">
              <div class="lunar">农历{{ item.data?.lunarDay }}</div>
              <div class="thing">
                <div class="content">宜：{{ item.data?.suitable }}</div>
                <div class="divider"></div>
                <div class="content">忌：{{ item.data?.avoid }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </PageWrapper>
</template>

<style lang="less" scoped>
.calendar {
  position: relative;
  width: 686rpx;

  margin: 242rpx auto 0;

  background-color: #FFF1D6;
  border-radius: 48rpx;

  .logo {
    position: absolute;
    top: -240rpx;
    left: -40rpx;

    width: 295rpx;
    height: 295rpx;
  }

  .title {
    position: absolute;
    top: -154rpx;
    right: 10rpx;

    width: 307rpx;
    height: 78rpx;
  }

  .date {
    width: 100%;
    height: 100rpx;

    border-radius: 48rpx 48rpx 0 0;
    background-color: #FFCC81;

    box-sizing: border-box;
    padding-left: 48rpx;
    padding-right: 34rpx;

    display: flex;
    justify-content: space-between;
    align-items: center;

    color: #BC4A1C;
    font-size: 40rpx;

    .change {
      padding: 6rpx 8rpx;

      border-radius: 43rpx;
      background-color: #FEDAAA;

      .inner {
        height: 68rpx;

        padding: 0 14rpx;

        border-radius: 43rpx;
        background-color: #F5E7CC;
        box-shadow: 0 0 10rpx 2rpx rgba(255, 188, 89, 0.50) inset;

        display: flex;
        align-items: center;

        font-size: 32rpx;
        line-height: 68rpx;

        .divider {
          width: 4rpx;
          height: 56rpx;

          margin: 0 14rpx;

          background-color: #EBC78C;
        }
      }
    }
  }

  .week {
    width: 100%;
    height: 100rpx;

    box-sizing: border-box;
    padding: 0 14rpx;

    background-color: #FFE1AC;

    display: grid;
    grid-template-columns: repeat(7, 1fr);

    color: #945D2C;
    font-size: 48rpx;
    font-weight: bold;
    line-height: 100rpx;
    text-align: center;
  }

  .day {
    width: 100%;

    box-sizing: border-box;
    padding: 0 14rpx 28rpx;

    display: grid;
    grid-template-columns: repeat(7, 1fr);

    .item {
      position: relative;
      height: 96rpx;

      box-sizing: border-box;

      color: #945D2C;
      font-size: 48rpx;
      font-weight: bold;
      line-height: 96rpx;
      text-align: center;

      &.right {
        border-right: 2rpx solid #F5D7A2;
      }

      &.bottom {
        border-bottom: 2rpx solid #F5D7A2;
      }

      &.active {
        color: #fff;
        background-color: #FA976D;
      }

      .info {
        position: absolute;
        bottom: 50%;
        width: 304rpx;
        height: 282rpx;

        border-radius: 48rpx;
        box-shadow: 0 6rpx 15rpx 2rpx rgba(243, 113, 0, 0.28), 0 0 4rpx 4rpx #58D994 inset;

        font-weight: normal;
        text-align: left;

        z-index: 1;

        .top-bar {
          padding: 8rpx 38rpx;

          display: flex;
          justify-content: space-between;
          align-items: center;

          color: #FFE1B6;
          font-size: 32rpx;
          line-height: 48rpx;

          .icon {
            width: 40rpx;
            height: 40rpx;

            transform: rotateZ(180deg);

            background-color: #F5D7AC;
            mask-size: 100% 100%;
          }
        }

        .box {
          position: relative;
          width: 268rpx;
          height: 200rpx;

          margin: 0 auto;

          border-radius: 16rpx;
          background-color: rgba(#000, .1);

          .lunar {
            margin-left: 16rpx;

            color: #F5D7AC;
            font-size: 24rpx;
            line-height: 40rpx;
          }

          .thing {
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 160rpx;

            border-radius: 16rpx;
            background-color: rgba(#fff, .1);
            box-shadow: 0 0 2rpx 4rpx rgba(53, 152, 92, .39) inset;

            overflow: hidden;

            .content {
              width: 100%;

              padding: 0 20rpx;

              color: #fff;
              font-size: 32rpx;
              line-height: 78rpx;
              white-space: nowrap;

              overflow: auto;
              touch-action: pan-x;
            }

            .divider {
              width: 244rpx;
              height: 2rpx;
              margin: 0 auto;

              background: rgba(52, 149, 89, 0.40);
            }
          }
        }
      }
    }
  }
}
</style>